import csv
from itertools import islice

import requests

# 使用csv读取测试用例
url = 'http://10.211.55.5:8080/jwshoplogin/user/login.do'
userinfo = {}
file2 = open('../../../interface_test/test_result/test_result.csv', 'w')
with open('../../test_data/independence_interface_data/login_userinfo.csv', 'r') as file1:
    reader1 = csv.reader(file1)
    for row in islice(reader1, 1, None):  # 使用islice方法跳过第一行
        userinfo["username"] = row[0]  # 用户名
        userinfo["password"] = row[1]  # 密码
        userinfo["expected_result"] = row[2]  # 预期结果
        responce = requests.post(url, data=userinfo).text  # 响应
        msg = responce.find(row[2])  # 查找预期结果
        if msg > 0:
            print("接口测试通过")
            file2.write(row[0] + ',' + row[1] + ',' + row[2] + ',' + '测试通过' + '\n')
        else:
            print("接口测试失败")
            file2.write(row[0] + ',' + row[1] + ',' + row[2] + ',' + '测试失败' + '\n')
file2.close()